import requests
import os
from os import system
from bs4 import BeautifulSoup

r = requests.get("http://www.avtaobao.tv")
host = r.url
new_url = host + "recent"
count = 1
for i in range(1, 10):
    html_doc = requests.get(new_url)
    soup = BeautifulSoup(html_doc.text, 'html.parser')
    video_href_list = soup.find_all('a', "thumbnail")
    for video_href in video_href_list:
        video_url = host + video_href.get("href")
        video_html_doc = requests.get(video_url)
        video_soup = BeautifulSoup(video_html_doc.text, 'html.parser')
        video_source = video_soup.find("source")
        if video_source is not None:
            file_name = ""
            while True:
                file_name = str(count) + ".mp4"
                if os.path.exists(file_name):
                    count += 1
                else:
                    break
            wget = "wget -t 5 -w 5 -T 15 -b -c -o /dev/null -O " + file_name + " '" + video_source.get("src") + "'"
            print(wget)
            system(wget)
    new_url = host + "recent/" + str(i)
